/*
 **@Author:刘淑钰
 **Created on 2021/11/28
 */
import java.util.*;
public class Main {

    public static ArrayList<String[]> S = new ArrayList<>();
    public void read_clause(String line, boolean reverse){
        line=line.replace(" ","");
        String[] line1 = line.split("\\|");
//        String[] line2;
//        if (reverse){
//
//            for(String i :line1){
//            line2=opposite(i);
//            }
//        }
        S.add(line1);

        }


//    public void opposite(String[] clause){
//    if(clause){}
//
//    }
//            if '~' in clause:
//            return clause.replace('~', '')
//            else:
//            return '~' + clause


    public void resolution(){
        boolean end=false;
        ArrayList<String[]> ret = new ArrayList<>();
        while(S!=null){
            if(end) break;
            String[] father=S.get(0);
            S.remove(0);
            for(String i:father){
                if(end) break;
                for(String mother: S ){
                    if(end) break;
                    j = list(filter(lambda x: x == opposite(i), mother))
                }
            }

        }


        }


    public static void main(String[] args){
    Main test = new Main();
    Scanner in=new Scanner(System.in);
    String s1=in.nextLine();
    String s2=in.nextLine();

    String[] s11=s1.split(",");
    String[] s22=s2.split(",");
    System.out.print(s11);

  for(String one : s11)
        {
            boolean reverse=false;
            test.read_clause(one,reverse);
        }
  ArrayList<String[]> results = new ArrayList<>();
       test.resolution();
//        boolean f = true;
//
//    for(String one : s22)
//    {
////        one=one.replace(" ","");
////        if opposite(one) in results:
////        ...
////    else:
////        f = False
//    }
//if(f){System.out.print("TRUE");}
//else{System.out.print("FALSE");}
    }
}


//"""
//样例输入
//p, ~q, ~p|~r|q
//r
//p|q, ~p|r, ~q|r
//~r
//p, ~p|q, ~p|~q|r
//p, r
//
//样例输出
//TRUE
//TRUE
//FALSE
//"""


//S = []
//T = dict()
//F = dict()
//U = dict()
//
////读子句，line是字符串，把字符串进行处理
//def read_clause(line, reverse=False):
//line = line.replace(' ', '').strip()
//line = line.split('|')
//if reverse:
//line = [opposite(_) for _ in line]
//S.append(line)
//
////将要证明的结论取反
//def opposite(clause):
//if '~' in clause:
//return clause.replace('~', '')
//else:
//return '~' + clause
//
////求解，S是一个数组
//def resolution():
//global S
//end = False
//
//ret = []
////只要数组不为空，到了末尾才结束
//while S:
//if end: break
//father = S.pop()
//for i in father[:]:
//if end: break
//for mother in S[:]:
//if end:
//break
//j = list(filter(lambda x: x == opposite(i), mother))
//if j == []:
//continue
//else:
//# print('\n亲本子句：' + ' ∨ '.join(father) + ' 和 ' + ' ∨ '.join(mother))
//father.remove(i)
//mother.remove(j[0])
//if father == [] and mother == []:
//# print('归结式：NIL')
//end = True
//elif father == []:
//# print('归结式：' + '|'.join(mother))
//ret.append('|'.join(mother))
//elif mother == []:
//# print('归结式：' + '|'.join(father))
//ret.append('|'.join(father))
//else:
//# print('归结式：' + '|'.join(father) + '|' + '|'.join(mother))
//ret.append('|'.join(father) + '|' + '|'.join(mother))
//return ret
//
//
////s1 = "p, ~q, ~p|~r|q"
////s2 = "r"
////
////s1 = "p|q, ~p|r, ~q|r"
////s2 = "~r"
////
////s1 = "p, ~p|q, ~p|~q|r"
////s2 = "p, r"
//
//
//for one in s1.split(","):
//read_clause(one)
//# for one in s2.split(","):
//#     read_clause(one, True)
//# print(S)
//results = resolution()
//
//f = True
//for one in s2.split(","):
//one.replace(' ', '')
//if opposite(one) in results:
//...
//else:
//f = False
//
//if f:
//print("TRUE")
//else:
//print("FALSE")
